package com.situ.hr4.w.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.hr4.pojo.ConfigFileFirstKind;
import com.situ.hr4.pojo.ConfigMajor;
import com.situ.hr4.pojo.ConfigMajorKind;
import com.situ.hr4.pojo.EngageMajorRelease;
import com.situ.hr4.w.service.ZWFBservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;

import java.beans.PropertyEditor;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;


@Controller
//职位发布管理
public class ZWFBcontroller {
    //时间类型转换器
    @InitBinder  //
    public void dateconvert(WebDataBinder bind){
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        PropertyEditor n=new CustomDateEditor(format, true);
        bind.registerCustomEditor(Date.class, n);
    }



    @Autowired
    ZWFBservice zwfb;
    //职位发布登记
    @RequestMapping("a")
    public String cxyjjg(Map map){
        //查询一级结构,绑
        List<ConfigFileFirstKind> list=zwfb.cx1();
        map.put("list",list );
        //职位分类查询,绑
        List<ConfigMajorKind> zwfl=zwfb.cxzwfl();
        map.put("zwfl",zwfl );
        return "/page/recruit/position/position_register.html";
    }
    //ajax通过一级结构查询二级结构
    @PostMapping("y")
    @ResponseBody
    public List<Map> y(int firstKind){
        //System.out.println(firstKind);
       //通过一级结构查询二级结构
        List<Map> list=zwfb.cx2(firstKind);
        //System.out.println(list.size());
        return list;
   }
   //ajax通过二级结构查询三级结构
   @PostMapping("Wy")
   @ResponseBody
   public List<Map> Wy(int secondKindId){
       //System.out.println(secondKindId);
       //通过二级结构查询三级结构
       List<Map> list=zwfb.cx3(secondKindId);
      // System.out.println(list.size());
       return list;
   }
   //ajax通过职位类型id查询职位名称
    @PostMapping("Wzwmc")
    @ResponseBody
    public List<ConfigMajor> Wzwmc(int id){
        List<ConfigMajor> list=zwfb.cxzwmc(id);
        return list;
    }
    //跳转到全查
    @PostMapping("Wzwfbtj")
    public String Wzwfbtj(EngageMajorRelease emrl){
       // System.out.println("三结构id:"+emrl.getThird_kind_id()+" 职位编号:"+emrl.getMajor_id()+
       //"招聘人数:"+emrl.getHuman_amount()+"招聘类型:"+emrl.getEngage_type()+"截至时间:"+
        //emrl.getDeadline()+"登记人:"+emrl.getRegister()+"变更人:"+emrl.getChanger()+
                //"登记时间"+emrl.getRegist_time()+"变更时间:"+emrl.getChange_time()+
        //"职位描述:"+emrl.getMajor_describe()+"招聘要求:"+emrl.getEngage_required());
        //职位发布添加
        zwfb.zwfbtj(emrl);
        return "redirect:a1";
    }





    //职位发布变更
    @RequestMapping("a1")
    public String a1(Map map,
                     @RequestParam(defaultValue = "1",required = false) Integer startPage,
                     @RequestParam(defaultValue = "3",required = false) Integer PageSize){
        PageHelper.startPage(startPage, PageSize ); //使用分页插件
        //全查
        List<Map> list=zwfb.zwfbqc();
        PageInfo pageInfo=new PageInfo(list,3); //保存分页信息
        map.put("list", list);
        map.put("pageInfo", pageInfo); //绑定分页信息
        return "/page/recruit/position/position_change_update.html";
    }
    //跳转到修改
        @GetMapping("tzx")
        public String tz(int id,Map map){
            //根据id查询
            Map e=zwfb.queryid(id);
            //获取登陆人


            //将登入人放入更新人中
            e.put("changer", "admin");
            map.put("e", e);
        return "/page/recruit/position/position_release_change.html";
        }

        //修改数据
        @PostMapping("xg")
        public String xg(EngageMajorRelease e){
            //根据id修改
            zwfb.xg(e);
            return "redirect:a1";
        }
        //删除
        @GetMapping("Wzwfbsc")
        public String Wzwfbsc(int id){
        //根据id删除
            zwfb.wzwfbsc(id);
        return "redirect:a1";
        }




        //职位发布查询
    @RequestMapping("a2")
    public String a2(Map map,
                     @RequestParam(defaultValue = "1",required = false) Integer startPage,
                     @RequestParam(defaultValue = "3",required = false) Integer PageSize){
        PageHelper.startPage(startPage, PageSize ); //使用分页插件
        //全查
        List<Map> list=zwfb.zwfbqc();
        PageInfo pageInfo=new PageInfo(list,3); //保存分页信息
        map.put("list", list);
        map.put("pageInfo", pageInfo); //绑定分页信息
        return "/page/recruit/position/position_release_search.html";
    }
    //跳转到申请该职位
    @RequestMapping("Wsqgzw")
    public String Wsqgzw(int id,Map map ){
        //通过id查询详情
        Map m=zwfb.queryid(id);
        map.put("m", m);
        return "/page/recruit/position/position_release_details.html";
    }

}
